import { EventHttp } from "../../../http/event"
import { computed, ref } from "vue"
/* 右上的饼状图 */
const pieData = ref([])
let res = await EventHttp.getPieData()
export const getEventPie = () => {
  if (res.code == 200) {
    //console.log(res.result)
    pieData.value = res.result
  }
  const pieOption = computed(() => {
    return {
      series: [
        {
          data: pieData.value,
          type: "pie",
          /* name: "类别", */
          label: {
            formatter: function (arg) {
              return arg.name/* +
                "类事故"  +
                arg.value +
                "个\n占比为" +
                arg.percent +
                "%" */
            },
            // 将标签的颜色改为和图中对应部分颜色一致 
            color: "inherit",
          },
          /* 改为圆环 */
          radius: ["35%", "55%"],
        },
      ],
      //添加标题,还是决定不添加这个图表的标题了,太乱了
      title: {
        text: "各类别事故占比",
        textStyle: {
          color: "grey",
        },
      },
      tooltip: {
        formatter: "{b}类事故比{d}%",
      },
      toolbox: {
        feature: {
          /* 实现导出图片 */
          saveAsImage: {},
        },
      },
      legend: {
        data: pieData.value.map((item) => item.name),
        x: "center",
        y: "bottom",
      },
    }
  })
  return {
    pieData,
    pieOption,
  }
}
